package com.android.lovingpet.mine.setting.accountsecurity;

import android.os.Bundle;
import android.support.annotation.Nullable;

import com.android.lovingpet.base.BasePresenter;
import com.android.lovingpet.common.Back;

public class AuthPresenter extends BasePresenter<IAuthContract.View> implements IAuthContract.Presenter {

    private IAuthContract.View view;

    public AuthPresenter(IAuthContract.View view) {
        this.view = view;
    }

    @Override
    public void sendEmail(String email) {
        view.showProgress();
        new AuthModel().authEmail(email, defaultBack());
    }

    @Override
    public void authIdCard(String name, String idCard) {
        view.showProgress();
        new AuthModel().authIdCard(name, idCard, defaultBack());
    }

    private Back defaultBack() {
        return new Back() {
            @Override
            public void onFailure(String meg) {
                view.hideProgress();
                view.showToast(meg);
            }

            @Override
            public void onSuccess(@Nullable Bundle bundle) {
                view.hideProgress();
                view.setView();
            }
        };
    }
}
